const UserDataMixins = {
	data() {
		return {
			navBarBackground: {
				backgroundColor: '#f2f2f2'
			},
			labelStyle: {
				paddingLeft: '30rpx',
				fontSize: '30rpx'
			},
			inputStyle: {
				textAlign: 'right'
			},

			params: [],
			paramTitle: '',
			selectorShow: false,
			selectorRange: [],
			selectorDefault: [],

			twoSelectShow: false,
			twoSelectRange: [],
			twoSelectRangeFirst: [],
			twoSelectRangeSecond: [],
			twoSelectDefault: [
				[],
				[]
			],
			searchPopupShow: false,
			searchPopupHeight: null,

			checkboxPopupShow: false,
			checkboxPopupHeight: null,


			regionList: [],
			regionShow: false,

			itemIndex: null,
			isLoad: false,
		}
	},
	methods: {
		getRegionListData() {
			this.$u.api.getRegionList().then(res => {
				const regionList = res.data.data;
				for (let i = 0; i < regionList.length; i++) {
					for (let j = 0; j < regionList[i].children.length; j++) {
						delete regionList[i].children[j].children;
					}
				}
				this.regionList = [{
					label: '中国',
					value: 86,
					children: [...regionList]
				}];
			});
		},
		clickInput(e) {
			const index = e.currentTarget.dataset.index;
			this.itemIndex = index;
			const param = this.params[index];
			this.paramTitle = `选择${param.name}`;
			switch (param.type) {
				case 10:
					this.selectorDefault = [];
					const selectorRange = param.items;
					for (let i = 0; i < selectorRange.length; i++) {
						if (selectorRange[i].name == param.setting) {
							this.selectorDefault.push(i);
							break;
						}
					}
					if (this.selectorDefault.length == 0) {
						this.selectorDefault.push([0])
					}
					this.selectorRange = selectorRange;
					this.selectorShow = true;
					break;
				case 20:
					this.paramTitle = `选择${param.name}(多选)`;
					if (!this.checkboxPopupHeight > 0) {
						const systemInfo = uni.getSystemInfoSync()
						this.checkboxPopupHeight = systemInfo.windowHeight - systemInfo.safeArea.top - 44 - 100;
					}
					this.checkboxPopupShow = true;
					break;
				case 30:
					this.regionShow = true;
					break;
				case 40:
					this.paramTitle = `搜索${param.name}`;
					if (!this.searchPopupHeight > 0) {
						const systemInfo = uni.getSystemInfoSync()
						this.searchPopupHeight = systemInfo.windowHeight - systemInfo.safeArea.top - 44 - 20;
					}
					this.searchPopupShow = true;
					break;
				case 50:
					this.twoSelectRange = this.$u.deepClone(param.items);
					this.twoSelectRangeFirst = this.$u.deepClone(this.twoSelectRange)
					this.twoSelectRangeSecond = this.$u.deepClone(this.twoSelectRange)
					this.twoSelectShow = true;
					this.twoSelectDefault = [0, 0]
					break;
				default:
					break;
			}
		},
		getAllParams() {
			const allParams = {}
			for (let i in this.params) {
				allParams[this.params[i].alias] = this.params[i].setting
			}
			return JSON.stringify(allParams)
		},
		confirmSelector(data) {
			if (data.length > 0) {
				this.$set(this.params[this.itemIndex], 'setting', this.selectorRange[data[0]].name);
			}
		},
		changeTwoSelect(data) {
			if (data.column == 0) {
				let twoSelectRangeSecond = this.$u.deepClone(this.twoSelectRange);
				for (let i = 0; i < data.index; i++) {
					twoSelectRangeSecond.splice(0, 1);
				}

				this.twoSelectRangeSecond = twoSelectRangeSecond;
				this.twoSelectDefault = [data.index, 0]
			} else {
				this.twoSelectDefault[data.column] = data.index
			}

		},
		confirmTwoSelector(data) {
			const setting1 = this.twoSelectRangeFirst[data[0]].name;
			const setting2 = this.twoSelectRangeSecond[data[1]].name;
			this.$set(this.params[this.itemIndex], 'setting', `${setting1}-${setting2}`);
		},
		confirmRegionPicker(data) {
			const regionArray = [data[0].label, data[1].label, data[2].label]
			this.$set(this.params[this.itemIndex], 'setting', regionArray.join(' '));
		},
		confirmParamSearch(data) {
			this.searchPopupShow = false;
			this.$set(this.params[this.itemIndex], 'setting', data.value);
		},
		confirmParamCheckbox(data) {
			this.checkboxPopupShow = false;
			this.$set(this.params[this.itemIndex], 'setting', data.value.join(','));
		}

	}
}
export default UserDataMixins;
